"""
we define a function `thread_function` that represents the work to be done in a thread. We then create multiple threads and start them using the start method. The join method is used to wait for all threads to complete before continuing the execution of the main thread.
"""


import threading
import time
import pathlib

# Define a function to be executed in a thread
def thread_function(name):
    print(f"Thread-{name} started")
    time.sleep(2)  # Simulate some work
    print(f"Thread-{name} completed")


def write(k):
    pathlib.Path(f"file{k}.txt").write_text('Hello, this is the {k}-th file.')

def remove(k):
    pathlib.Path(f"file{k}.txt").unlink()

# Create and start multiple threads
threads = [threading.Thread(target=thread_function, args=(k,)) for k in range(10)]

for thread in threads:
    thread.start()

# Wait for all threads to complete
for thread in threads:
    thread.join()

print("All threads completed")
